Public Class frmLineaPed
    Private _Descuento As Double
    Private _Nuevo As Boolean
    Private _NLinea As Integer
    Dim MiCursorRaton As New GestProyecto
    
    Private Sub mnuCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuCancelar.Click

        Me.Dispose()

    End Sub

    Private Sub btnBArticulo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnBArticulo.Click

        MiCursorRaton.CursorRaton(True)

        txtDto.Text = 0
        txtCantidad.Text = 0
        txtPB.Text = 0
        txtCuota.Text = 0
        txtTotal.Text = 0
        frmInicio.MifrmBArticulos = New frmBArticulos
        frmInicio.MifrmBArticulos.lblFormulario.Text = "Pedidos"
        frmInicio.MifrmBArticulos.Show()

        MiCursorRaton.CursorRaton(False)

    End Sub

    Private Sub CalcularPrecio()

        If txtCantidad.Text = 0 Then
            txtTotal.Text = 0
            Exit Sub
        End If

        If Not txtDto.Text = 0 Then
            _Descuento = CDbl(txtPB.Text) * (CDbl(txtDto.Text) / 100)
        Else
            _Descuento = 0
        End If

        txtTotal.Text = CDbl(CDbl(txtPB.Text) - _Descuento) * CInt(txtCantidad.Text)

        If frmInicio.MifrmPedido.IVA = False Then
            txtCuota.Text = 0
            Exit Sub
        End If
        If Not txtTotal.Text = 0 Then
            If frmInicio.MifrmPedido.RE = False Then
                txtCuota.Text = CInt(txtTotal.Text) * (CDbl(txtIVA.Text) / 100)
            Else
                txtCuota.Text = CDbl(txtTotal.Text) * ((CDbl(txtIVA.Text) + CDbl(txtRE.Text)) / 100)
            End If
        End If

    End Sub

    Private Sub txtPB_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPB.KeyPress

        MiCursorRaton.CursorRaton(True)

        If InStr(1, "0123456789,-" & Chr(8), e.KeyChar) = 0 Then
            e.Handled = True
        Else
            e.Handled = False
        End If

        MiCursorRaton.CursorRaton(False)

    End Sub

    Private Sub txtDto_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtDto.KeyPress

        MiCursorRaton.CursorRaton(True)

        If InStr(1, "0123456789,-" & Chr(8), e.KeyChar) = 0 Then
            e.Handled = True
        Else
            e.Handled = False
        End If

        MiCursorRaton.CursorRaton(False)

    End Sub

    Private Sub txtCantidad_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtCantidad.KeyPress

        MiCursorRaton.CursorRaton(True)

        If InStr(1, "0123456789-" & Chr(8), e.KeyChar) = 0 Then
            e.Handled = True
        Else
            e.Handled = False
        End If

        MiCursorRaton.CursorRaton(False)

    End Sub

    Private Sub txtCantidad_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtCantidad.TextChanged

        MiCursorRaton.CursorRaton(True)

        If txtCantidad.Text = "" Or txtDto.Text = "" Then
            txtTotal.Text = 0
            txtCuota.Text = 0
            Exit Sub
        Else
            CalcularPrecio()
        End If

        MiCursorRaton.CursorRaton(False)

    End Sub

    Private Sub txtDto_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtDto.TextChanged

        MiCursorRaton.CursorRaton(True)

        If txtDto.Text = "" Or txtDto.Text = "" Then Exit Sub
        CalcularPrecio()

        MiCursorRaton.CursorRaton(False)

    End Sub

    Private Sub txtPB_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtPB.TextChanged

        MiCursorRaton.CursorRaton(True)

        If txtPB.Text = "" Or txtDto.Text = "" Then
            txtTotal.Text = 0
            txtCuota.Text = 0
            Exit Sub
        Else
            CalcularPrecio()
        End If

        MiCursorRaton.CursorRaton(False)

    End Sub

    Private Sub mnuAceptar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAceptar.Click

        MiCursorRaton.CursorRaton(True)

        If _Nuevo = True Then
            frmInicio.MifrmPedido.MiLineasPedido.add(New LineaPedido(txtCodigo.Text, txtArticulo.Text, CInt(txtCantidad.Text), CDbl(txtPB.Text) _
            , _Descuento, CDec(txtIVA.Text), CDec(txtRE.Text), CDbl(txtCuota.Text), CDbl(txtTotal.Text), True))
        Else
            With frmInicio.MifrmPedido.MiLineasPedido
                .RemoveAt(_NLinea)
                .Insert(_NLinea, (New LineaPedido(txtCodigo.Text, txtArticulo.Text, CInt(txtCantidad.Text), CDbl(txtPB.Text) _
            , _Descuento, CDec(txtIVA.Text), CDec(txtRE.Text), CDbl(txtCuota.Text), CDbl(txtTotal.Text), True)))
            End With
        End If
        frmInicio.MifrmPedido.Mostrar()

        MiCursorRaton.CursorRaton(False)

        Me.Dispose()

    End Sub

 
    Friend WriteOnly Property Nuevo() As Boolean

        Set(ByVal value As Boolean)
            _Nuevo = value
        End Set

    End Property

    Friend WriteOnly Property NLinea() As Integer
        Set(ByVal value As Integer)
            _NLinea = value
        End Set
    End Property
End Class